var geoInfo = {};

function geoPlugin (info) {
    geoInfo["currencyCode"] = info["geoplugin_currencyCode"];
    geoInfo["countryCode"]  = info["geoplugin_countryCode"];
}

function getCurrencyCode() {
    try {
        geoInfo["currencyCode"] = geoplugin_currencyCode()
    } catch (e) {}

    return geoInfo["currencyCode"]
}

function getCountryCode() {
    try {
        geoInfo["countryCode"] = geoplugin_countryCode()
    } catch (e) {}

    return geoInfo["countryCode"]
}

function getGeoInfo() {
//    // first step
//    $.ajax({url: "http://www.geoplugin.net/json.gp?ip=" + ip, jsonp: true, async:false});
//    if (geoInfo["currencyCode"] || geoInfo["countryCode"]) {
//        return;
//    }

//    //second step
//    $.ajax({url: "http://www.geoplugin.net/javascript.gp", jsonp: true, async:false});
    getCurrencyCode();
    getCountryCode();
    if (geoInfo["currencyCode"] || geoInfo["countryCode"]) {
        return;
    }

//    // third step
//    $.ajax({ // TODO hide key
//        url: "http://api.ipinfodb.com/v2/ip_query_country.php?key=842ab6b446bb01799ced51f8772a9c88e4c004e930db60510f8232bc4c2df451&ip=" + ip + "&output=json",
//        async:false,
//        dataType:"json",
//        success: function(msg){
//            geoInfo["countryCode"] = msg["CountryCode"];
//        }
//    })
}

getGeoInfo();